## Coding and decoding Rep(3)

from PyM import show

# Coding function
def f(u): return [u,u,u]

# Decoding function, assuming x = [a,b,c]
def g(x): 
    [a,b,c] = x
    if a==b or a==c: return a
    if b==c: return b
    return 'Decoder error'

show(f(1))

show(g([0,0,0]),g([1,0,0]),g([0,1,0]),g([0,0,1]))

show(g([1,1,0]),g([1,0,1]),g([0,1,1]),g([1,1,1]))

show (g([2,5,2]))

show (g([3,2,1]))


'''
The reader may experiment by changing the python code. 
For example, an alternative decoding function could be
(assuming that a, b, c are bit values):
'''

def h(x): 
    c = x.count(0)
    if c>1: return 0
    return 1


show(h([0,0,0]),h([1,0,0]),h([0,1,0]),h([0,0,1]))

show(h([1,1,0]),h([1,0,1]),h([0,1,1]),h([1,1,1]))

